#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
# @Time   : 2022/3/29 14:59
# @Author : 闫峰
描述: 发送企业微信通知
"""

import requests

from util.exception.exception import MyCustomException
from util.times_tool.time_control import now_time


class WeChatSend:
    """
    企业微信消息通知
    """

    def __init__(self,url):
        self.headers = {"Content-Type": "application/json"}
        self.url = url

    def send_markdown(self, content):
        """
        发送 MarkDown 类型消息
        :param content: 消息内容，markdown形式
        :return:
        """
        _data = {"msgtype": "markdown", "markdown": {"content": content}}
        res = requests.post(
            # url="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=52ee53b6-0f41-4a76-99f8-1297de37ffc7", json=_data,
            url=self.url, json=_data,
            headers=self.headers)
        if res.json()['errcode'] != 0:
            print(res.json())
            raise MyCustomException("企业微信「MarkDown类型」消息发送失败")

